﻿using System.IO;
using JetBlack.IO;

namespace JetBlack.TopicBus.Messages
{
    internal class ForwardedSubscriptionRequest : Message
    {
        public readonly int ClientId;
        public readonly string Topic;
        public readonly bool IsAdd;

        public ForwardedSubscriptionRequest(int clientId, string topic, bool isAdd)
            : base(MessageType.ForwardedSubscriptionRequest)
        {
            ClientId = clientId;
            Topic = topic;
            IsAdd = isAdd;
        }

        new static public ForwardedSubscriptionRequest Read(Stream reader)
        {
            int clientId = reader.ReadInt32();
            string topic = reader.ReadString();
            bool isAdd = reader.ReadBoolean();
            return new ForwardedSubscriptionRequest(clientId, topic, isAdd);
        }

        public override Stream Write(Stream writer)
        {
            base.Write(writer);
            writer.Write(ClientId);
            writer.Write(Topic);
            writer.Write(IsAdd);
            return writer;
        }

        override public string ToString()
        {
            return string.Format("{0} {1} {2} {3}", MessageType, ClientId, Topic, IsAdd);
        }
    }
}
